package system.login.web;

import org.springframework.beans.factory.annotation.Autowired;

import system.login.service.SecurityBoxService;
import system.user.dto.User;

import com.core.framework.web.easyweb.EasyAction;
import com.core.framework.web.easyweb.annotation.MethodType;
import com.core.framework.web.easyweb.annotation.Namespace;

@Namespace("/sys")
public class LoginAction extends EasyAction{
	@Autowired
	SecurityBoxService securityBoxService;
	public String toLogin()
	{
		return "/common/login.htm";
	}
	@MethodType(MethodType.JSON)
	public void check()
	{
		String loginName = this.getValue("loginName");
		String password = this.getValue("password");
		User user = securityBoxService.check(loginName, password);
		if(user!=null)
		{
				this.request.getSession().setAttribute("user", user);
				this.jsonResult.success=true;
				this.jsonResult.data="登录成功";
		}
		else
		{
				this.jsonResult.success=false;
				this.jsonResult.data="登录失败";
		}
	}
	public String toSucc()
	{
		return "/common/back/system/user/userIndex.htm";
	}
	public String toFail()
	{
		return this.toLogin();
	}
	public void writeCookies()
	{
		
	}

}
